import { Command } from 'commander';
import { generateFromFile, generateFromAttributes } from './lib/generator.js';

const program = new Command();

program
  .name('nestc')
  .description('Quick CRUD generator for NestJS + Sequelize + Swagger')
  .version('1.0.0');

program
  .argument('[modelOrPath]', 'Model name in src/models or absolute/relative file path')
  .option('--model <name>', 'Model name, e.g. Activation')
  .option('--attributes <fields>', 'Fields like: code:string,email:string,count:number')
  .action(async (modelOrPath: string | undefined, options: any) => {
    try {
      if (options.model && options.attributes) {
        await generateFromAttributes(options.model, options.attributes);
      } else if (modelOrPath) {
        await generateFromFile(modelOrPath);
      } else {
        console.error('❌ Please provide a model file/path or --model with --attributes');
        process.exit(1);
      }
      console.log('✅ Done.');
    } catch (e: any) {
      console.error('❌ Error:', e.message || e);
      process.exit(1);
    }
  });

program.parse();
